package com.xgz.processor.beanpost;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.SmartInstantiationAwareBeanPostProcessor;
import org.springframework.stereotype.Component;

import java.lang.reflect.Constructor;

/**
 * 实现 智能实例化注入 Bean后置增强
 * @author xgz
 */
@Component
public class MySmartInstantiationAwareBeanPostProcessor implements SmartInstantiationAwareBeanPostProcessor {

	public MySmartInstantiationAwareBeanPostProcessor(){
		System.out.println("My SmartInstantiationAwareBeanPostProcessor 构造器调用...");
	}

	@Override // 预测Bean的类型，可以改变组件类型。 SmartInstantiationAwareBeanPostProcessor
	public Class<?> predictBeanType(Class<?> beanClass, String beanName) throws BeansException {
		// 以类型获取所有 Bean名字，就会调用这个方法。
		return null;
	}

	@Override //决定候选的构造器
	public Constructor<?>[] determineCandidateConstructors(Class<?> beanClass, String beanName) throws BeansException {
		// 这里可以返回一个指定的构造器
		return null;
	}

	@Override // 获取早期bean的引用
	public Object getEarlyBeanReference(Object bean, String beanName) throws BeansException {
		return SmartInstantiationAwareBeanPostProcessor.super.getEarlyBeanReference(bean, beanName);
	}
}
